//
//  SYChengYuanDetailsView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/22.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYChengYuanDetailsView.h"
#import "SYCYHeaderView.h"
#import "SYAttendLectureTableViewCell.h"
#import "SYAttendZhuZiTableViewCell.h"
#import "SYGuoKeTableViewCell.h"
#import "SYResourcesTableViewCell.h"
#import "SYXinDeView.h"
#import "SYPlayerViewController.h"

@interface SYChengYuanDetailsView () <UITableViewDelegate,UITableViewDataSource,SYAttendLectureTableDelegate,SYResourcesTableViewDelegate>

@property (strong, nonatomic) SYBackTopView *backView;//顶部viwe
@property (strong, nonatomic) UITableView *curTableView;// 表
@property (strong, nonatomic) SYCYHeaderView *cyHeaderView;//表头
//@property (strong, nonatomic) SYResourcesTableViewCell *gkCell;
@property (strong, nonatomic) NSMutableArray *ziyuanArr;//资源申请
@property (strong, nonatomic) SYXinDeView *xindeView;//学习心得
@end


@implementation SYChengYuanDetailsView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
        [self initSubView];
    }
    return self;
}

- (void)initSubView {
    [self addSubview:self.backView];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    self.ziyuanArr = [SYZiYuanShenQingModel monishuju];
    //表
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_bottom).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
        make.bottom.equalTo(self.mas_bottom).offset(-14);
    }];
}
#pragma mark - tab
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 4) {//资源申请信息
        return 1;
    } else {
        return 5;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 4) {//资源申请信息
        return 5 * 50;
    } else {
        return 44;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 190;
    }  else {
        return 50;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 ||indexPath.section == 2) {//听课心得 空讲信息
        SYAttendLectureTableViewCell *attendCell = [tableView dequeueReusableCellWithIdentifier:@"SYAttendLectureTableViewCell" forIndexPath:indexPath];
        attendCell.selectionStyle = UITableViewCellSelectionStyleNone;
        attendCell.delegate = self;
        [attendCell attendLectureTableViewCellIndexPath:indexPath stusa:indexPath.section];
        return attendCell;
    } else if (indexPath.section == 1) {
        SYAttendZhuZiTableViewCell *zzCell = [tableView dequeueReusableCellWithIdentifier:@"SYAttendZhuZiTableViewCell" forIndexPath:indexPath];
        zzCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [zzCell attendZhuZiTableViewCellIndexPath:indexPath];
        return zzCell;
    } else if (indexPath.section == 3) { //过客信息
        SYGuoKeTableViewCell *gkCell = [tableView dequeueReusableCellWithIdentifier:@"SYGuoKeTableViewCell" forIndexPath:indexPath];
        gkCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [gkCell attendGuoKeTableViewCellIndexPath:indexPath];
        return gkCell;
    } else { //资源申请信息 SYResourcesTableViewCell
        SYResourcesTableViewCell *gkCell = [tableView dequeueReusableCellWithIdentifier:@"SYResourcesTableViewCell" forIndexPath:indexPath];
        gkCell.selectionStyle = UITableViewCellSelectionStyleNone;
        gkCell.delegate = self;
        [gkCell lncomingData:self.ziyuanArr indexPath:indexPath];
        return gkCell;
    }
    
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    if (section == 0) {
        SYCYHeaderView *headerView = [[SYCYHeaderView alloc] init];
        [view addSubview:headerView];
        
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.right.equalTo(view);
        }];
    } else {
        SYTopView *topView = [[SYTopView alloc] init];

        [view addSubview:topView];
        topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
        [topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(view);
            make.left.equalTo(view.mas_left).offset(14);
            make.right.equalTo(view.mas_right).offset(-14);
        }];
        if (section == 1) {//柱子高
            topView.titleLab.text = @"逐字稿";
        } else if (section == 2) {//空讲信息
            topView.titleLab.text = @"空讲信息";
        } else if (section == 3) {//过客信息
            topView.titleLab.text = @"过课信息";
        } else if (section == 4) {//资源申请
            topView.titleLab.text = @"资源申请信息";
        }
    }
    UIView *fgxView = [UIView new];
    fgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    [view addSubview:fgxView];
    [fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(view.mas_bottom).offset(0);
        make.left.equalTo(view.mas_left).offset(28);
        make.right.equalTo(view.mas_right).offset(-28);
        make.height.mas_equalTo(1);
    }];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top).offset(1);
        make.left.equalTo(view.mas_left).offset(14);
        make.right.equalTo(view.mas_right).offset(-14);
        make.height.mas_equalTo(20);
    }];
    UIView *fgxView = [UIView new];
    fgxView.backgroundColor = [UIColor colorWithHexString:@"#CCCCCC"];
    [view addSubview:fgxView];
    [fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_top).offset(0);
        make.left.equalTo(view.mas_left).offset(28);
        make.right.equalTo(view.mas_right).offset(-28);
        make.height.mas_equalTo(1);
    }];
    return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {//逐字稿
        [self attendLectureTableType:SYDetailsTypeZhuZiGao];
    } else if (indexPath.section == 3) {
        [self attendLectureTableType:SYDetailsTypeGuoKe];
    } else if (indexPath.section == 2) {//空讲。。视频播放
        SYPlayerViewController *playerVC = [[SYPlayerViewController alloc] init];
        playerVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:playerVC animated:YES completion:nil];
    }
    
}


#pragma mark - SYAttendLectureTableDelegate
//听课信息
- (void)attendLectureTableType:(SYDetailsType)type {
    _xindeView = [[SYXinDeView alloc] initWithFrame:CGRectMake(kScreen_WIDTH, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20) detailsType:type xindeViewType:SYXinDeViewTypeShiFu];
    [self addSubview:_xindeView];
    __weak typeof(self) weakSelf = self;
    [UIView animateWithDuration:kAnimate animations:^{
        weakSelf.xindeView.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), kScreen_HEIGHT-20);
    }];
}
#pragma mark - g过客资源 SYResourcesTableViewDelegate
- (void)resourcesTableView:(SYDetailsType)type {
    [self attendLectureTableType:type];
}

#pragma mark - set
//头部
- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"成员详情" baseView:self];
    }
    return _backView;
}
- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _curTableView.backgroundColor = [UIColor whiteColor];
        [_curTableView registerCellWithClassNames:@[@"SYResourcesTableViewCell"]];
        [_curTableView registerCellWithNIbNames:@[@"SYAttendLectureTableViewCell",@"SYAttendZhuZiTableViewCell",@"SYGuoKeTableViewCell"]];
    }
    return _curTableView;
}
- (SYCYHeaderView *)cyHeaderView {
    if (!_cyHeaderView) {
        _cyHeaderView = [[SYCYHeaderView alloc] init];
    }
    return _cyHeaderView;
}


@end





























